package com.ruoyi.web.controller.shop;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.shop.domain.MonthInventory;
import com.ruoyi.shop.service.IMonthInventoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品月份Controller
 * 
 * @author ruoyi
 * @date 2024-06-12
 */
@RestController
@RequestMapping("/shop/month")
public class MonthInventoryController extends BaseController
{
    @Autowired
    private IMonthInventoryService monthInventoryService;

    /**
     * 查询商品月份列表
     */
    @PreAuthorize("@ss.hasPermi('shop:month:list')")
    @GetMapping("/list")
    public TableDataInfo list(MonthInventory monthInventory)
    {
        startPage();
        List<MonthInventory> list = monthInventoryService.selectMonthInventoryList(monthInventory);
        return getDataTable(list);
    }

    @GetMapping("/list2")
    public TableDataInfo list2(MonthInventory monthInventory)
    {
        startPage();
        List<MonthInventory> list2 = monthInventoryService.selectMonthInventoryList2(monthInventory);
        return getDataTable(list2);
    }

    @GetMapping("/list3")
    public TableDataInfo list3(MonthInventory monthInventory)
    {
        startPage();
        List<MonthInventory> list3 = monthInventoryService.selectMonthInventoryList3(monthInventory);
        return getDataTable(list3);
    }

    /**
     * 导出商品月份列表
     */
    @PreAuthorize("@ss.hasPermi('shop:month:export')")
    @Log(title = "商品月份", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MonthInventory monthInventory)
    {
        List<MonthInventory> list = monthInventoryService.selectMonthInventoryList(monthInventory);
        ExcelUtil<MonthInventory> util = new ExcelUtil<MonthInventory>(MonthInventory.class);
        util.exportExcel(response, list, "商品月份数据");
    }

    /**
     * 获取商品月份详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:month:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(monthInventoryService.selectMonthInventoryById(id));
    }

    /**
     * 新增商品月份
     */
    @PreAuthorize("@ss.hasPermi('shop:month:add')")
    @Log(title = "商品月份", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MonthInventory monthInventory)
    {
        return toAjax(monthInventoryService.insertMonthInventory(monthInventory));
    }

    /**
     * 修改商品月份
     */
    @PreAuthorize("@ss.hasPermi('shop:month:edit')")
    @Log(title = "商品月份", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MonthInventory monthInventory)
    {
        return toAjax(monthInventoryService.updateMonthInventory(monthInventory));
    }

    /**
     * 删除商品月份
     */
    @PreAuthorize("@ss.hasPermi('shop:month:remove')")
    @Log(title = "商品月份", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(monthInventoryService.deleteMonthInventoryByIds(ids));
    }
}
